#include "badminton.h"
#include<QTimer>

Badminton::Badminton(QPixmap pixmap, QGraphicsItem *parent)
    : QObject(), QGraphicsPixmapItem(pixmap, parent), m_velocityX(0), m_velocityY(0)
{
    this->setPixmap(pixmap);
    m_moveTimer = new QTimer(this);
    connect(m_moveTimer, &QTimer::timeout, this, &Badminton::move);
    m_moveTimer->start(10);
}

void Badminton::applyGravity()
{
    m_velocityY += GRAVITY;
}

void Badminton::hit(double forceX, double forceY)
{
    m_velocityX = forceX;
    m_velocityY = forceY;
}

void Badminton::move()
{
    applyGravity();
    setPos(x() + m_velocityX, y() + m_velocityY);
}
